#include<bits/stdc++.h>
using namespace std;
struct node
{
	int d,v,a;
}car[100100];
int main()
{
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
	int t;
	cin>>t;
	while(t--)
	{
  		int m,n,l,V;
  		int p[100100];
  		bool vis[100100]={0};
  		scanf("%d%d%d%d",&n,&m,&l,&V);
  		for(int i=1;i<=n;i++)
  		{
  			scanf("%d%d%d",&car[i].d,&car[i].v,&car[i].a);
  		}
  		for(int i=1;i<=m;i++)
  			cin>>p[i];
  		int ans=0;
  		for(int i=1;i<=n;i++)
  			{
  				if(car[i].v>V&&car[i].d<=p[m])
  					ans++;
  			}
  		cout<<ans<<' '<<m-1;
	}
	return 0;
}